package com.wx.wxsecondskill.dao;

import java.util.List;

import com.wx.wxsecondskill.po.SecondsKillGoods;
import com.wx.wxsecondskill.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


/**
 * @ClassName GoodsDao
 * @Author wx
 * @Description 商品dao
 * @Date 2018-11-15-22:03
 */
@Mapper
public interface GoodsDao {


	/**
	 * @methodName: listGoodsVo
	 * @author: wx
	 * @description: 查询商品列表
	 * @param
	 * @date: 2018/11/15
	 * @return: java.util.List<com.wx.wxsecondskill.vo.GoodsVo>
	 */
	@Select("select g.*,mg.stock_count, mg.start_date, mg.end_date,mg.seconds_kill_price from t_seconds_kill_goods mg left join t_goods g on mg.goods_id = g.id")
	List<GoodsVo> listGoodsVo();

	/**
	 * @methodName: getGoodsVoByGoodsId
	 * @author: wx
	 * @description: 查询商品信息
	 * @param goodsId
	 * @date: 2018/11/15
	 * @return: com.wx.wxsecondskill.vo.GoodsVo
	 */
	@Select("select g.*,mg.stock_count, mg.start_date, mg.end_date,mg.seconds_kill_price from t_seconds_kill_goods mg left join t_goods g on mg.goods_id = g.id where g.id = #{goodsId}")
	GoodsVo getGoodsVoByGoodsId(@Param("goodsId") Integer goodsId);

	/**
	 * @methodName: reduceStock
	 * @author: wx
	 * @description: 减商品库存
	 * @param secondsKillGoods
	 * @date: 2018/11/15
	 * @return: void
	 */
	@Update("update t_seconds_kill_goods set stock_count = stock_count - 1 where goods_id = #{goodsId} and stock_count > 0")
	int reduceStock(SecondsKillGoods secondsKillGoods);
	
}
